Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
calibration_storage.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void SaveMagCalibrationToNVM (SensorFusionGlobals *sfg)
 
void SaveGyroCalibrationToNVM (SensorFusionGlobals *sfg)
 
void SaveAccelCalibrationToNVM (SensorFusionGlobals *sfg)
 
void EraseMagCalibrationFromNVM (void)
 
void EraseGyroCalibrationFromNVM (void)
 
void EraseAccelCalibrationFromNVM (void)
 

Detailed Description

Users who are not using NXP hardware will need to supply their own drivers in place of those defined here.

Definition in file calibration_storage.h.

Function Documentation

void EraseAccelCalibrationFromNVM ( void  )

Definition at line 188 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

189 {
190  uint8_t *pSrc, *pDst; // scratch pointers
191  int16_t i; // loop counter
192  uint8_t iNVMBuffer[256]; // NVM write buffer
193 
194  // copy existing magnetic, gyro and accelerometer calibrations to buffer
195  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
196  pDst = iNVMBuffer;
197  for (i = 0; i < 256; i++)
198  *(pDst++) = *(pSrc++);
199 
200  // set no gyroscope calibration in header
201  iNVMBuffer[ACCEL_NVM_OFFSET] = iNVMBuffer[ACCEL_NVM_OFFSET + 1] = iNVMBuffer[ACCEL_NVM_OFFSET + 2] = iNVMBuffer[ACCEL_NVM_OFFSET + 3] = 0xFF;
202 
203  // write the buffer to flash
204  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
205 
206  return;
207 }
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EraseGyroCalibrationFromNVM ( void  )

Definition at line 167 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

168 {
169  uint8_t *pSrc, *pDst; // scratch pointers
170  int16_t i; // loop counter
171  uint8_t iNVMBuffer[256]; // NVM write buffer
172 
173  // copy existing magnetic, gyro and accelerometer calibrations to buffer
174  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
175  pDst = iNVMBuffer;
176  for (i = 0; i < 256; i++)
177  *(pDst++) = *(pSrc++);
178 
179  // set no gyroscope calibration in header
180  iNVMBuffer[GYRO_NVM_OFFSET] = iNVMBuffer[GYRO_NVM_OFFSET + 1] = iNVMBuffer[GYRO_NVM_OFFSET + 2] = iNVMBuffer[GYRO_NVM_OFFSET + 3] = 0xFF;
181 
182  // write the buffer to flash
183  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
184 
185  return;
186 }
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void EraseMagCalibrationFromNVM ( void  )

Definition at line 146 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

147 {
148  uint8_t *pSrc, *pDst; // scratch pointers
149  int16_t i; // loop counter
150  uint8_t iNVMBuffer[256]; // NVM write buffer
151 
152  // copy existing magnetic, gyro and accelerometer calibrations to buffer
153  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
154  pDst = iNVMBuffer;
155  for (i = 0; i < 256; i++)
156  *(pDst++) = *(pSrc++);
157 
158  // set no magnetic calibration in header
159  iNVMBuffer[MAG_NVM_OFFSET] = iNVMBuffer[MAG_NVM_OFFSET + 1] = iNVMBuffer[MAG_NVM_OFFSET + 2] = iNVMBuffer[MAG_NVM_OFFSET + 3] = 0xFF;
160 
161  // write the buffer to flash
162  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
163 
164  return;
165 }
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SaveAccelCalibrationToNVM ( SensorFusionGlobals sfg)

Definition at line 112 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

113 {
114 #if F_USING_ACCEL
115  uint8_t *pSrc, *pDst; // scratch pointers
116  int16_t i; // loop counter
117  uint8_t iNVMBuffer[256]; // NVM write buffer
118  uint32_t itmp32;
119 
120  // copy existing magnetic, gyro and accelerometer calibrations to buffer
121  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
122  pDst = iNVMBuffer;
123  for (i = 0; i < 256; i++)
124  *(pDst++) = *(pSrc++);
125  // default to no gyroscope calibration in header
126  iNVMBuffer[ACCEL_NVM_OFFSET] = iNVMBuffer[ACCEL_NVM_OFFSET + 1] = iNVMBuffer[ACCEL_NVM_OFFSET + 2] = iNVMBuffer[ACCEL_NVM_OFFSET + 3] = 0xFF;
127 
128  // [0-3]: four byte header denoting accelerometer calibration present
129  itmp32 = 0x12345678;
130  pSrc = (uint8 *) &itmp32;
131  pDst = iNVMBuffer + ACCEL_NVM_OFFSET;
132  for (i = 0; i < 4; i++)
133  *(pDst++) = *(pSrc++);
134 
135  // [4-87]: 21 precision accelerometer calibration floats totalling 84 bytes
136  pSrc = (uint8 *) &(sfg->AccelCal);
137  for (i = 0; i < 84; i++)
138  *(pDst++) = *(pSrc++);
139 
140  // write the buffer contents to NVM
141  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
142 #endif
143  return;
144 }
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SaveGyroCalibrationToNVM ( SensorFusionGlobals sfg)

Definition at line 73 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

74 {
75 #if F_USING_GYRO && (F_9DOF_GBY_KALMAN || F_6DOF_GY_KALMAN)
76  uint8_t *pSrc, *pDst; // scratch pointers
77  int16_t i; // loop counter
78  uint8_t iNVMBuffer[256]; // NVM write buffer
79  uint32_t itmp32;
80 
81  // copy existing magnetic, gyro and accelerometer calibrations to buffer
82  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
83  pDst = iNVMBuffer;
84  for (i = 0; i < 256; i++)
85  *(pDst++) = *(pSrc++);
86  // default to no gyroscope calibration in header
87  iNVMBuffer[GYRO_NVM_OFFSET] = iNVMBuffer[GYRO_NVM_OFFSET + 1] = iNVMBuffer[GYRO_NVM_OFFSET + 2] = iNVMBuffer[GYRO_NVM_OFFSET + 3] = 0xFF;
88 
89  // define the four header bytes
90  // [0-3]: four byte header denoting gyro calibration present
91  itmp32 = 0x12345678;
92  pSrc = (uint8 *) &itmp32;
93  pDst = iNVMBuffer + GYRO_NVM_OFFSET;
94  for (i = 0; i < 4; i++)
95  *(pDst++) = *(pSrc++);
96 
97  // [4-15]: 3 gyro offset floats totalling 12 bytes
98 #if F_9DOF_GBY_KALMAN
99  pSrc = (uint8 *) sfg->SV_9DOF_GBY_KALMAN.fbPl;
100 #elif F_6DOF_GY_KALMAN
101  pSrc = (uint8 *) sfg->SV_6DOF_GY_KALMAN.fbPl;
102 #endif
103  for (i = 0; i < 12; i++)
104  *(pDst++) = *(pSrc++);
105 
106  // write the buffer contents to NVM
107  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
108 #endif
109  return;
110 }
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)
#define F_6DOF_GY_KALMAN
6DOF accel and gyro (Kalman) algorithm selector - 0x2000 to include, 0x0000 otherwise ...

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SaveMagCalibrationToNVM ( SensorFusionGlobals sfg)

Definition at line 39 of file calibration_storage.c.

Referenced by DecodeCommandBytes().

40 {
41 #if F_USING_MAG
42  uint8_t *pSrc, *pDst; // scratch pointers
43  int16_t i; // loop counter
44  uint8_t iNVMBuffer[256]; // NVM write buffer (smallest size writeable to flash)
45  uint32_t itmp32;
46 
47  // copy existing magnetic, gyro and accelerometer calibrations to buffer
48  pSrc = (uint8 *) CALIBRATION_NVM_ADDR;
49  pDst = iNVMBuffer;
50  for (i = 0; i < 256; i++)
51  *(pDst++) = *(pSrc++);
52  // default to no magnetic calibration in header
53  iNVMBuffer[MAG_NVM_OFFSET] = iNVMBuffer[MAG_NVM_OFFSET + 1] = iNVMBuffer[MAG_NVM_OFFSET + 2] = iNVMBuffer[MAG_NVM_OFFSET + 3] = 0xFF;
54 
55  // fill the buffer with the magnetic calibration in bytes 0 to 67 (total 68 bytes)
56  // [0-3]: four byte header denoting magnetic calibration present
57  itmp32 = 0x12345678;
58  pSrc = (uint8 *) &itmp32;
59  pDst = iNVMBuffer + MAG_NVM_OFFSET;
60  for (i = 0; i < 4; i++)
61  *(pDst++) = *(pSrc++);
62  // [4-67]: magnetic calibration: 15x float + 1x int32 total 64 bytes
63  pSrc = (uint8 *) &(sfg->MagCal);
64  for (i = 0; i < 64; i++)
65  *(pDst++) = *(pSrc++);
66 
67  // write the whole buffer contents to NVM
68  NVM_SetBlockFlash(iNVMBuffer, CALIBRATION_NVM_ADDR, 256);
69 #endif // if F_USING_MAG
70  return;
71 }
MagCalibration MagCal
mag cal storage
uint8_t uint8
Definition: sensor_fusion.h:58
byte NVM_SetBlockFlash(uint8_t *Source, uint32_t Dest, uint16_t Count)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: